Skip to content

Added loadCert methods to WiFiClientSecure #1959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2018
Merged

Added loadCert methods to WiFiClientSecure #1959

merged 1 commit into from
Nov 19, 2018

Conversation

lbernstone
Copy link
Contributor

Fixes #1957.
Allows a file object to be used as a certificate in WiFiClientSecure.

@me-no-dev me-no-dev merged commit 65c861a into espressif:master Nov 19, 2018
@stickbreaker
Copy link
Contributor

stickbreaker commented Jan 28, 2020

@lbernstone I have some question on these load* function using _loadStream().

from the original issue #1957 the OP said he used these three function to configure the secureClient:

In the ESP8266 I have stored a root CA certificate a device certificate and a private key in SPIFFS which I then load into WiFiClientSecure using the loadCACert, loadCertificate and loadPrivateKey methods which accept a Stream as a parameter and load from SPIFFS no problem.

My question is that _loadStream() uses a static char * for the stream buffer. So, every call to _loadStream() reuses the same pointer, It free's the buffer if necessary before each use, BUT prior calls to load* stored the address that is now being free'd? Am I totally confused(very possible).

If I understand the OP's usage, he will use:

WifiClientSecure client;
client.loadCACert(file);// which reads from Stream and stores into heap buffer address also held in static char *
client.loadCertificate(file2);// which frees buffer containing CACertificate? then reallocates buffer for Certificate
client.loadPrivateKey(file3); // which frees buffer containing Certificate?

Now:
client._CA_cert point to freed memory/invalid
client._cert points to freed memory/invalid
client.private_key points to private_key/valid

I am working #3679
Chuck.

@stickbreaker
Copy link
Contributor

@lbernstone I'm thinking that these pointers need a type field, something to mark constant or heap. So that the destructor can clean up, right now the WifiSecureClient() destructor ignores these pointers.

Chuck.

@lbernstone
Copy link
Contributor Author

Yes. Messy, messy. I'll be afk for a couple days, but will take a look this weekend. Maybe just needs the destructor to manually free the memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WifiClientSecure - Enhancement - add load methods.
3 participants